import os, django, datetime, sys
sys.path.insert(0, "../")
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'ayc_bbs.settings')
django.setup()

import uuid
import json
from django.conf import settings
from forum.models import Topic, Attachments, ActivityTopic
from user_app.models import AccountInfo
from django.db import connection
from django.db.models import Count
from utils import redis_client_db1
from utils.encrypt_util import md5
from utils import wx_method

if __name__ == '__main__':
    pass
    # tc = Topic.objects.raw("SELECT *, num_replies+num_views as total FROM `forum_topic` order by total desc")[:10]
    # print(tc)
    # at = Attachments.objects.filter(id__in=['1','2','3'])
    # print(at)
    # tc = Topic.objects.filter(category='0').order_by("-created_on")[:6]
    # print(tc)
    # SQL = r"SELECT forum_comment.created_by_id, count(forum_comment.created_by_id) as total FROM forum_comment left join forum_topic on forum_comment.topic_id = forum_topic.id group by forum_comment.created_by_id order by total desc;"
    # with connection.cursor() as cursor:
    #     cursor.execute(SQL)
    #     for row in cursor.fetchall():
    #         account_id = row[0]
    #         total = row[1]
    #         print(account_id, total)
    password = 'zx913618259'
    print(md5(settings.PASSWORD_SALT + password))
    # uid = uuid.uuid4()
    # print(uid)
    # today = datetime.date.today()
    # qz = AccountInfo.objects.filter(create_time__gt=today)
    # print(qz)
    # start_time, end_time = "2021-03-12", "2021-03-15"
    # result = Topic.objects.filter(created_on__range=(start_time, end_time)).values_list("subject", flat=True)
    # print(result)
    # topic_id = "20"
    scene = "BarDetail_id=612"
    page = "pages/signUp/signUp"
    #file_name = 'topic_%s' % topic_id
    file_name = 'activity_qrcode4'
    code, result = wx_method.create_qrcode(file_name=file_name, scene=scene, page=page, is_hyaline=False, auto_color=True)
    print(code, result)
